package com.xdf.zipperdye.controller;

import com.xdf.zipperdye.model.Product;
import com.xdf.zipperdye.service.ProductService;
import com.xdf.zipperdye.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "品名")
@CrossOrigin
@RestController
@RequestMapping("/product")
@Slf4j
public class ProductController {
    @Autowired
    private ProductService service;

    @ApiOperation(value="根据主键删除品名", notes="根据主键删除品名。返回 Integer", produces="application/json")
    @GetMapping("/deleteByPrimaryKey/{iid}")
    public JsonResult deleteByPrimaryKey(@PathVariable Integer iid){
        return JsonResult.ok(service.deleteByPrimaryKey(iid));
    }

    @ApiOperation(value="完全新增品名", notes="完全新增品名。返回 Integer", produces="application/json")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody Product record){
        return JsonResult.ok(service.insert(record));
    }

    @ApiOperation(value="选择性新增品名", notes="选择性新增品名。返回 Integer", produces="application/json")
    @PostMapping("/insertSelective")
    public JsonResult insertSelective(@RequestBody Product record){
        return JsonResult.ok(service.insertSelective(record));
    }

    @ApiOperation(value="根据品名查询获取", notes="根据品名查询获取。", produces="application/json")
    @GetMapping("/selectByPrimaryKey/{iid}")
    public JsonResult selectByPrimaryKey(@PathVariable Integer iid){
        return JsonResult.ok(service.selectByPrimaryKey(iid));
    }

    @ApiOperation(value="选择性修改", notes="选择性更新。", produces="application/json")
    @PostMapping("/updateByPrimaryKeySelective")
    public JsonResult updateByPrimaryKeySelective(@RequestBody Product record){
        return JsonResult.ok(service.updateByPrimaryKeySelective(record));
    }

    @ApiOperation(value="完全修改", notes="完全修改。", produces="application/json")
    @PostMapping("/updateByPrimaryKey")
    public JsonResult updateByPrimaryKey(@RequestBody Product record){
        return JsonResult.ok(service.updateByPrimaryKey(record));
    }

    @ApiOperation(value="查询获取所有", notes="查询获取所有。返回数组", produces="application/json")
    @GetMapping("/selectAll")
    public JsonResult selectAll(){
        return JsonResult.ok(service.selectAll());
    }
}
